//
//  MachineReportViewController.m
//  EPBPro
//
//  Created by wucha on 2018/8/13.
//  Copyright © 2018年 fc. All rights reserved.
//

#import "MachineReportViewController.h"
#import "HttpReportAction.h"
#import "PNBarChart.h"
#import "AreaMachineInfo.h"

@interface MachineReportViewController ()<PNChartDelegate>
@property (nonatomic,strong) PNBarChart *barChart;

@end

@implementation MachineReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleName = @"地区机器报表";
    self.view.backgroundColor = [UIColor whiteColor];
    static NSNumberFormatter *barChartFormatter;
    if (!barChartFormatter) {
        barChartFormatter = [[NSNumberFormatter alloc] init];
        barChartFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
        barChartFormatter.allowsFloats = NO;
        barChartFormatter.maximumFractionDigits = 0;
    }
//    self.titleLabel.text = @"Bar Chart";
    
    self.barChart = [[PNBarChart alloc] initWithFrame:CGRectMake(0, 135.0, SCREEN_WIDTH, 200.0)];
    //        self.barChart.showLabel = NO;
//    self.barChart.yLabelFormatter = ^(CGFloat yValue) {
//        return [barChartFormatter stringFromNumber:@(yValue)];
//    };
    
//    self.barChart.yChartLabelWidth = 20.0;
//    self.barChart.chartMarginLeft = 30.0;
//    self.barChart.chartMarginRight = 10.0;
//    self.barChart.chartMarginTop = 5.0;
//    self.barChart.chartMarginBottom = 10.0;
//    
//    
//    self.barChart.labelMarginTop = 5.0;
    self.barChart.showChartBorder = YES;
   
    
    self.barChart.isGradientShow = YES;
    self.barChart.isShowNumbers = YES;

    
    [self.barChart strokeChart];
    
    self.barChart.delegate = self;
    
    [self.view addSubview:self.barChart];
    
    
    [HttpReportAction getAreaMachine:^(id result, NSError *error) {
        if (!error) {
            NSArray *array = result;
            [self setData:array];
        }
    }];
    
}

-(void)setData:(NSArray*)array{
    NSMutableArray *xLabel = [NSMutableArray array];
    NSMutableArray *yValue = [NSMutableArray array];

    for (AreaMachineInfo *areaMachineInfo in array) {
        [xLabel addObject:areaMachineInfo.regionName];
        [yValue addObject:areaMachineInfo.equipmentNumber];
    }
    [self.barChart setXLabels:xLabel];
    [self.barChart setYValues:yValue];
    [self.barChart setStrokeColors:@[PNGreen, PNGreen, PNRed, PNGreen, PNGreen, PNGreen, PNRed, PNGreen]];
    [self.barChart strokeChart];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
